﻿using strange.extensions.context.api;
using strange.extensions.dispatcher.eventdispatcher.api;
using strange.extensions.mediation.impl;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class BallView : View
{
    private Text ScoreText;

    [Inject(ContextKeys.CONTEXT_VIEW)]//可以得到ContextView的物体
    public GameObject ContextView { get; set; }

    [Inject]
    public IEventDispatcher dispatcher { get; set; }

    private ExitDirector exitDirector;
    public void Init()
    {
        ScoreText = ContextView.transform.Find("Canvas/Score").GetComponent<Text>();
        exitDirector = ContextView.transform.Find("Ball").GetComponent<ExitDirector>();//得到ExitDirector 
        exitDirector.dispatcher.AddListener(Events.GET_REWARD, OnGetReward);//监听到事件后处理回调                                    
    }
    //更新UI
    public void UpdateScore(int score)
    {
        ScoreText.text = score.ToString();
    }
    public void OnGetReward()
    {
        dispatcher.Dispatch(Events.FOR_ADD_SCORE);//派发出一个事件
        SoundManager._Instance.PlaySoundByName("sfx_point");//播放得分音效
    }
}
